<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2015/1/24
  Time: 11:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="session"/>
<!DOCTYPE html>

<html>
<head>
    <title>招投标管理</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${path}/plugins/jquery-easyui-1.4.1/themes/icon.css">
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function(){
            //查询
            $("#search").click(function(){
                $('#ttAll').datagrid('load',{
                    title:$("#title").val()
                });
            });
        });
    </script>

</head>
<body  class="easyui-layout">
<div region="center" style="padding:5px;" border="false">
<div id="tabs" class="easyui-tabs" style="width:100%;height:700px">
<div title="全部" style="padding:10px">
    <!--列表-->
    <table id="ttAll" class="easyui-datagrid"
           data-options="singleSelect:true,collapsible:true,url:'${path}/bid/view.do',
       method:'get',toolbar:'#tb',pagination:'true',fit:'true'">
        <thead>
        <tr>
            <th data-options="field:'titleCn',align:'center',width:80">项目名(中文)</th>
            <th data-options="field:'titleEn',align:'center',width:80">项目名（英文）</th>
            <th data-options="field:'descriptionCn',align:'center',width:80">描述（中文）</th>
            <th data-options="field:'descriptionEn',align:'center',width:80">描述（英文）</th>
            <th data-options="field:'pic',align:'center',width:80,formatter:function(v){return '<img width=\'30px\' height=\'30px\' src=/'+v+'>'}">图片</th>
            <th data-options="field:'firstClass',align:'center',width:80">一级分类</th>
            <th data-options="field:'secondClass',align:'center',width:80">二级分类</th>
            <th data-options="field:'style',align:'center',width:80">风格</th>
            <th data-options="field:'skillName',align:'center',width:80">技能</th>
            <th data-options="field:'progress',align:'center',width:80">进度</th>
            <th data-options="field:'property',align:'center',width:80,formatter:function(v){if(v == 106101){ return '官方外包'}else{return '普通外包';}}">外包类型</th>
            <th data-options="field:'STATUS',align:'center',width:80">状态</th>
            <th data-options="field:'publish_time',align:'center',width:80">发布时间</th>
            <th data-options="field:'bid_time',align:'center',width:80">竞标时间（天）</th>
            <th data-options="field:'lang',align:'center',width:80">任务国际</th>
            <th data-options="field:'property',align:'center',width:80">任务性质</th>
            <th data-options="field:'bibTotal',align:'center',width:80">中标数量</th>
            <th data-options="field:'addvalue_id',align:'center',width:80,formatter:function(v){if(v == 3){ return '是'}else{return '否';}}">是否语言支持</th>
            <th data-options="field:'id',align:'center',width:80,formatter: rowformatter">操作</th>
        </tr>
        </thead>
    </table>
</div>
</div>
</div>
<!--头工具项-->
<div id="tb" style="padding:2px 5px;">
    项目名: <input class="easyui-textbox" name="title" id="title" style="width:110px">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="search" stab="ttAll">查找</a>
</div>
<!--翻译-->
<div id="w" class="easyui-window" title="翻译" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:700px;height:400px;padding:10px;">
    <div style="padding:10px 10px 10px 10px" id="itemDetail">
        <div class="easyui-panel" title="翻译">
            <table border="1px" cellpadding="0" cellspacing="0" bordercolor= "#95B8E7" width="100%">
                <tr>
                    <th style="padding: 5px">描述</th>
                    <th style="padding: 5px">中文</th>
                    <th style="padding: 5px">英文</th>
                </tr>
                <tbody id="itemInfo">
                    <tr>
                        <td style="padding: 5px">
                            标题
                        </td>
                        <td style="padding: 5px"><input type="text" id="titleCn" style="width: 265px;"></td>
                        <td style="padding: 5px"><input type="text" id="titleEn" style="width: 265px;"></td>
                    </tr>
                    <tr>
                        <td style="padding: 5px">
                            任务描述
                        </td>
                        <td style="padding: 5px"><textarea id="descriptionCn" style="width: 265px;height: 150px"></textarea></td>
                        <td style="padding: 5px"><textarea id="descriptionEn" style="width: 265px;height: 150px"></textarea></td>
                    </tr>
                </tbody>
                <input type="hidden" id="itemId">
                <input type="hidden" id="lastIndex">
            </table>
            <p><a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateW()">保存翻译</a></p>
        </div>
    </div>
</div>
<script>
    function rowformatter(value,row,index){
        if(row.addvalue_id == 3){
            return  '<a href="#" onclick="showW('+index+')">翻译</a>';
        }else{
            return '';
        }

    }
    function showW(index){
        //本行数据
        var row = $('#ttAll').datagrid('getData').rows[index];
        $("#titleCn").val(row.titleCn);
        $("#titleEn").val(row.titleEn);
        $("#itemId").val(row.id);
        $("#lastIndex").val(index);
        $("#descriptionCn").val(row.descriptionCn);
        $("#descriptionEn").val(row.descriptionEn);

        //给文本框加上只读属性前，先移除以前的只读属性
        $("#titleCn").removeAttr("readonly");
        $("#descriptionCn").removeAttr("readonly");
        $("#titleEn").removeAttr("readonly");
        $("#descriptionEn").removeAttr("readonly");
        if(row.lang == "zh_cn" || row.lang == ''){
            $("#titleCn").attr("readonly","readonly");
            $("#descriptionCn").attr("readonly","readonly");
        }else{
            $("#titleEn").attr("readonly","readonly");
            $("#descriptionEn").attr("readonly","readonly");
        }
        $('#w').window('open');
    }

    function updateW(){
        var index = $("#lastIndex").val();;
        var row = $('#ttAll').datagrid('getData').rows[index];
        if(row.lang == "zh_cn" || row.lang == ''){
            updateEn();
        }else{
            updateCn();
        }
    }

    //翻译为英文
    function updateEn(){

        if($("#titleEn").val() == ''){
            alert("英文标题翻译不能为空");
            return;
        }
        if($("#descriptionEn").val() == ''){
            alert("英文描述翻译不能为空");
            return;
        }

        $.post("${path}/bid/translationEn.do",{
            itemId:$("#itemId").val(),
            titleEn:$("#titleEn").val(),
            descriptionEn:$("#descriptionEn").val()
        },function(data){
            if(data.errormsg == undefined){

                $('#ttAll').datagrid('updateRow', {
                    index:$("#lastIndex").val(),
                    row : {
                        titleEn:$("#titleEn").val(),
                        descriptionEn:$("#descriptionEn").val()
                    }
                });
                $("#titleCn").val("");
                $("#titleEn").val("");
                $("#itemId").val("");
                $("#descriptionCn").val("");
                $("#descriptionEn").val("");
                $("#lastIndex").val("");

                $('#w').window('close');
            }else{
                alert("翻译失败！");
            }
        },"json");
    }
    //翻译为中文
    function updateCn(){

        if($("#titleCn").val() == ''){
            alert("中文标题翻译不能为空");
            return;
        }
        if($("#descriptionCn").val() == ''){
            alert("中文描述翻译不能为空");
            return;
        }

        $.post("${path}/bid/translationCn.do",{
            itemId:$("#itemId").val(),
            titleEn:$("#titleCn").val(),
            descriptionEn:$("#descriptionCn").val()
        },function(data){
            if(data.errormsg == undefined){

                $('#ttAll').datagrid('updateRow', {
                    index:$("#lastIndex").val(),
                    row : {
                        titleCn:$("#titleCn").val(),
                        descriptionCn:$("#descriptionCn").val()
                    }
                });
                $("#titleCn").val("");
                $("#titleEn").val("");
                $("#itemId").val("");
                $("#descriptionCn").val("");
                $("#descriptionEn").val("");
                $("#lastIndex").val("");

                $('#w').window('close');
            }else{
                alert("翻译失败！");
            }
        },"json");
    }
</script>
</body>
</html>
